﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AJAX_learning
{
	public partial class Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			TimeTextBox.Text = DateTime.Now.ToString();
			if(this.IsPostBack)
			{
				TimeTextBox.Text += "PostBack";
			}
		}
	}

	public sealed class SimpleWaitLock : IDisposable
	{
		private Semaphore m_AvailableResources;
		public SimpleWaitLock(Int32 maximumConcurrentThreads)
		{
			m_AvailableResources = new Semaphore(maximumConcurrentThreads, maximumConcurrentThreads);
		}
		public void Enter()
		{
			// Wait efficiently in the kernel for resource access, then return
			m_AvailableResources.WaitOne();
		}
		public void Leave() 
		{
			// This thread doesn’t need access anymore; another thread can have it
			m_AvailableResources.Release();
		}
		public void Dispose() { m_AvailableResources.Close(); }
	}
}